#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2024/3/11 14:10
# @Author  : jeff
# @FileName: user_service
from src.enums.status_enum import Status
from src.service.base_service import BaseService
from src.model.user_model import User
from flask import request
from loguru import logger
from src.utils.jwt_utils import JwtUtils


class Login(BaseService):
    @staticmethod
    @BaseService.transactional
    def login_service():
        """
        Log in
        :return:
        """
        username = request.json.get("username")
        password = request.json.get("password")
        logger.info(f'username:{username},password:{password}')
        user = User.query_by_user(username, password)
        if not user:
            return Status.USER_NOT_EXIST
        token = JwtUtils.create_new_token(username, password)
        return Status.OK, {'token': token}
